<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @property CI_Input $input
 * @property CI_Session $session
*/
class MY_Controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load_lib();

        $this->load_model();

        //$this->lang->load('main_lang', 'english');
        session_start();
    }

    public function load_lib()
    {
        $this->load->helper('language');
        $this->load->helper('url');
        $this->load->helper('date');
        $this->load->library('session');
        $this->load->library('uri');
        $this->load->helper('email');
        $this->load->library('email');

        /*if( strpos(base_url(),'example.com') !== false || strpos(base_url(),'ktshouse.localhost') !== false) //luan's localhost
        {
			$config['hostname'] = "localhost";
            $config['username'] = "root";
            $config['password'] = "vertrigo";
            $config['database'] = "ktshouse";
            $config['dbdriver'] = "mysql";
            $config['dbprefix'] = "";
            $config['pconnect'] = FALSE;
            $config['db_debug'] = TRUE;
            $config['cache_on'] = FALSE;
            $config['cachedir'] = "";
            $config['char_set'] = "utf8";
            $config['dbcollat'] = "utf8_general_ci";
		}
		else if(strpos(base_url(),'localhost') !== false )
        {
            $config['hostname'] = "localhost";
            $config['username'] = "root";
            $config['password'] = "admin";
            $config['database'] = "electronic_shop";
            $config['dbdriver'] = "mysql";
            $config['dbprefix'] = "";
            $config['pconnect'] = FALSE;
            $config['db_debug'] = TRUE;
            $config['cache_on'] = FALSE;
            $config['cachedir'] = "";
            $config['char_set'] = "utf8";
            $config['dbcollat'] = "utf8_general_ci";
        }
        else
        {
            $config['hostname'] = "localhost";
            $config['username'] = "root";
            $config['password'] = "admin";
            $config['database'] = "electronic_shop";
            $config['dbdriver'] = "mysql";
            $config['dbprefix'] = "";
            $config['pconnect'] = FALSE;
            $config['db_debug'] = TRUE;
            $config['cache_on'] = FALSE;
            $config['cachedir'] = "";
            $config['char_set'] = "utf8";
            $config['dbcollat'] = "utf8_general_ci";
        }
        $this->load->database($config);*/

        $upload_config['upload_path'] = 'uploads/';
        $upload_config['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
        $this->load->library('upload', $upload_config);
    }

    public function load_model()
    {
    }

    function array_to_object($array)
    {
        if(!is_array($array))
        {
            return $array;
        }

        $object = new stdClass();
        if (is_array($array) && count($array) > 0)
        {
            foreach ($array as $name=>$value) {
                $name = strtolower(trim($name));
                if (!empty($name)) {
                    $object->$name = $this->array_to_object($value);
                }
            }
            return $object;
        }
        else
        {
            return FALSE;
        }
    }

    public function send_mail($from,$to,$name,$subject,$message)
    {
        $config[]= array('protocol'=>'smtp',
            'smtp_host'=>'localhost',
            'smtp_user'=>'info@integration.vn',
            'smtp_pass'=>'',
            'smtp_port'=>'');

        $this->email->initialize($config);

        $this->email->set_newline("\r\n");

        //From email and sender name
        $this->email->from($from,$name);

        //To addresses. if more than once, add it as comma separated
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($message);
        $this->email->send();

    }
}